package com.jg.xmlSchema2JsonSchema.xsd;

import com.jg.xmlSchema2JsonSchema.xsd.util.XsdUtil;
import org.w3c.dom.Element;

import java.util.List;

/**
 * @author czg
 */
public class XsRestriction {
    private Element element;
    private String base;
    private String annotation;
    private String id;

    public XsRestriction(Element element) {
        this.element = element;
        getData();
    }

    private void getData() {
        XsAnnotation xsAnnotation = XsdUtil.getAnnotation(element);
        if (xsAnnotation != null) {
            annotation = xsAnnotation.getText();
        }
        base = element.getAttribute("base");
        id = element.getAttribute("id");
    }

    public String getBase() {
        return base;
    }

    public String getAnnotation() {
        return annotation;
    }

    public String getId() {
        return id;
    }

    public List<XsEnumeration> getEnumerations() {
        List<XsEnumeration> resultList = XsdUtil.getEnumerations(element);
        return resultList;
    }

    public List<XsPattern> getPatterns() {
        List<XsPattern> resultList = XsdUtil.getPatterns(element);
        return resultList;
    }

    public Element getXmlElement() {
        return element;
    }

    public List<XsAttribute> getAttributes() {
        List<XsAttribute> resultList = XsdUtil.getAttributes(element);
        return resultList;
    }

    public XsLength getXsLength() {
        return XsdUtil.getXsLength(element);
    }

    public XsMinLength getXsMinLength() {
        return XsdUtil.getXsMinLength(element);
    }

    public XsMaxLength getXsMaxLength() {
        return XsdUtil.getXsMaxLength(element);
    }

    public XsWhiteSpace getXsWhiteSpace() {
        return XsdUtil.getXsWhiteSpace(element);

    }

}
